package cn.wanho.service.Impl;

import cn.wanho.mapper.ExamPaperMapper;
import cn.wanho.mapper.ExamSummaryMapper;
import cn.wanho.rvo.*;
import cn.wanho.service.exam.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private ExamSummaryMapper examSummaryMapper;
    @Resource
    private ExamPaperMapper examPaperMapper;

    @Override
    public ResultVO queryStudentAllScore(Integer userId) {
        List<ScoreAndTeacherVO> list =  examSummaryMapper.queryStudentScore(userId);
        if(!list.isEmpty()){
            return ResultVO.success(ResultEnum.QUERY_SCORE_TEACHER_SUCCESS.getResCode(), ResultEnum.QUERY_STUDENT_SUCCESS.getResMsg(),list);
        }else{
            return ResultVO.faiure(ResultEnum.QUERY_SCORE_TEACHER_FAILURE.getResCode(), ResultEnum.QUERY_STUDENT_FAILURE.getResMsg());
        }
    }

    @Override
    public ResultVO studentApplyFor(Long subjectId, Integer userId) {
        List<ApplyForVO> list = examSummaryMapper.applyForReconsider(subjectId,userId);
        if(!list.isEmpty()){
            return ResultVO.success(ResultEnum.APPLY_FOR_SUCCESS.getResCode(), ResultEnum.APPLY_FOR_SUCCESS.getResMsg(),list);
        }else{
            return ResultVO.faiure(ResultEnum.APPLY_FOR_FAILURE.getResCode(), ResultEnum.APPLY_FOR_FAILURE.getResMsg());
        }
    }

    @Override
    public ResultVO queryPaper(Integer userId) {
        List<PaperVO> paperVOS = examPaperMapper.queryPaper(userId);
        if (paperVOS.size()!=0){
           return ResultVO.success(ResultEnum.QUERYPAPER_SUCCESS.getResCode(),ResultEnum.QUERYPAPER_SUCCESS.getResMsg(),paperVOS);
        }
        return ResultVO.faiure(ResultEnum.QUERYPAPER_FAILURE.getResCode(), ResultEnum.QUERYPAPER_FAILURE.getResMsg());
    }
}
